#include "Demo.h"

#define IDT_HWNDVISIBLE_MONITOR (WM_APP + 7000)


void _CenterWindow(HWND hWnd, HWND hParent = NULL)
{
	assert(NULL != hWnd && IsWindow(hWnd));

	if (NULL == hParent || IsWindow(hParent))
	{
		hParent = GetDesktopWindow();
	}

	if (NULL != hWnd && IsWindow(hWnd))
	{
		RECT rtWnd;
		RECT rtParent;
		GetClientRect(hWnd, &rtWnd);
		GetClientRect(hParent, &rtParent);

		int nW	= rtWnd.right - rtWnd.left;
		int nH	= rtWnd.bottom - rtWnd.top;

		int nX	= ((rtParent.right - rtParent.left) - nW) >> 1;
		int nY	= ((rtParent.bottom - rtParent.top) - nH) >> 1;
	
		SetWindowPos(hWnd, NULL, nX, nY, nW, nH, SWP_NOACTIVATE);
	}
	
	return;
}

LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	_CenterWindow(hWnd);


	SetTimer(hWnd, IDT_HWNDVISIBLE_MONITOR, 500, NULL);

	return 0;
}

LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hDC = BeginPaint(hWnd, &ps);
	
	const TCHAR* szInfo	= _T("Hello, Win32 App");
	RECT rtWnd;
	GetClientRect(hWnd, &rtWnd);
	SetBkMode(hDC, TRANSPARENT);
	SetTextColor(hDC, RGB(200, 100, 200));
	DrawText(hDC, szInfo, -1, &rtWnd, DT_SINGLELINE|DT_VCENTER|DT_CENTER);

	EndPaint(hWnd, &ps);

	return 0;
}

LRESULT OnTimer(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	if (wParam == IDT_HWNDVISIBLE_MONITOR)
	{
		RECT rtWnd;
		GetClientRect(hWnd, &rtWnd);

		HDC hDC = GetDC(hWnd);

		if (RectVisible(hDC, &rtWnd))
		{
			SetWindowText(hWnd, _T("You can see me"));
		} else {
			SetWindowText(hWnd, _T("You can't see me"));
		}

		ReleaseDC(hWnd, hDC);
	}

	return 0;
}

LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	KillTimer(hWnd, IDT_HWNDVISIBLE_MONITOR);
	PostQuitMessage(0);

	return 0;
}




































